<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="商品类目" prop="categoryId">
        <treeselect
          style="width: 220px;"
          v-model="queryParams.categoryId"
          :options="categoryList"
          :normalizer="normalizer"
          placeholder="请选择商品类目"
        />
      </el-form-item>
      <el-form-item label="类目状态" prop="isAutoOptimize">
        <el-select v-model="queryParams.isAutoOptimize" placeholder="请选择类目状态" clearable>
          <el-option v-for="dict in dict.type.auto_optimize_category_status" :key="dict.value" :label="dict.label"
                     :value="dict.value"/>
        </el-select>
      </el-form-item>
      <el-form-item label="商品标题" prop="subject">
        <el-input
          v-model="queryParams.subject"
          placeholder="请输入商品标题"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="产品Id" prop="id">
        <el-input
          v-model="queryParams.id"
          @keyup.enter.native="handleQuery"
          placeholder="产品Id搜索"
          clearable
        >
        </el-input>
      </el-form-item>
      <el-form-item label="商品链接" prop="collectUrl">
        <el-input
          v-model="queryParams.collectUrl"
          placeholder="请输入商品链接"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="采集商品" prop="isCollect">
        <el-select v-model="queryParams.isCollect" placeholder="是否为采集商品" clearable>
          <el-option v-for="dict in collectList" :key="dict.value" :label="dict.label"
                     :value="dict.value"/>
        </el-select>
      </el-form-item>
      <el-form-item label="编辑" prop="isEdit">
        <el-select v-model="queryParams.isEdit" placeholder="是否已编辑" clearable>
          <el-option v-for="dict in editList" :key="dict.value" :label="dict.label"
                     :value="dict.value"/>
        </el-select>
      </el-form-item>
      <el-form-item label="运费试算" prop="isFreight">
        <el-select v-model="queryParams.isFreight" placeholder="是否已运费试算" clearable>
          <el-option v-for="dict in freightList" :key="dict.value" :label="dict.label"
                     :value="dict.value"/>
        </el-select>
      </el-form-item>
      <el-form-item label="翻译" prop="isTranslate">
        <el-select v-model="queryParams.isTranslate" placeholder="是否已翻译" clearable>
          <el-option v-for="dict in translateList" :key="dict.value" :label="dict.label"
                     :value="dict.value"/>
        </el-select>
      </el-form-item>
      <el-form-item label="采集人员" prop="collectUserId">
        <el-select v-model="queryParams.collectUserId" placeholder="请选择采集人员" clearable size="small">
          <el-option
            v-for="dict in userDict"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="发布测试状态：" prop="isUploadTest" label-width="120px">
        <el-select v-model="queryParams.isUploadTest" clearable placeholder="请选择发布测试状态">
          <el-option v-for="item in dict.type.test_release_status" :key="item.value" :label="item.label"
                     :value="item.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="产品库搜索" prop="isAddSellerProduct" label-width="100px">
        <!-- <el-input v-model="queryParams.isAddSellerProduct" placeholder="产品库搜索"></el-input> -->
        <el-select v-model="queryParams.isAddSellerProduct" clearable placeholder="产品库搜索">
          <el-option v-for="ie in addSellerProductList" :key="ie.value" :label="ie.label" :value="ie.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="skuCode" prop="skuCode">
        <el-input v-model="queryParams.skuCode" placeholder="skuCode搜索"></el-input>
      </el-form-item>
      <el-form-item label="品牌" prop="brandId">
        <el-select v-model="queryParams.brandId" placeholder="请选择品牌" clearable size="small">
          <el-option
            v-for="dict in brandList"
            :key="dict.value"
            :label="dict.lable"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="商品标签" prop="classifyLabel">
        <el-select
          v-model="queryParams.classifyLabel"
          placeholder="请选择"
          clearable>
          <el-option
            v-for="dict in tagList"
            :key="dict.value"
            :label="dict.lable"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleImport"
          v-hasPermi="['gather:collectProduct:query']"
        >公共采集库导入
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          size="mini"
          :disabled="multiple"
          @click="handleUploadTestBatch"
        >批量测试发布
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          size="mini"
          :disabled="multiple"
          @click="handlePublishBatch"
        >批量刊登
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          size="mini"
          @click="handleReporting"
        >生成报告
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-table v-loading="loading" :data="collectProductList" @selection-change="handleSelectionChange" stripe border>
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="产品Id" align="center" prop="id" width="100"/>
      <el-table-column label="商品标题" align="center" prop="subject"/>
      <el-table-column label="商品图" align="center" prop="white" width="100">
        <template slot-scope="scope">
          <!--          <imagePreview :src="scope.row.white" width="60px" height="60px"/>-->
          <imagePreview v-if="scope.row.imageURLs" :src="scope.row.imageURLs.split(';')[0]" width="60px" height="60px"/>
          <!--          <el-button type="text" size="mini" @click="openChooseImage(scope.row)">选择图片</el-button>-->
          <el-button type="text" size="mini" @click="openEditDetailImg(scope.row,'0')">编辑详情图</el-button>
          <el-button type="text" size="mini" @click="openEditDetailImg(scope.row,'1')">编辑商品主图</el-button>
        </template>
      </el-table-column>
      <el-table-column label="商品类目" align="center" prop="categoryName" width="100">
        <template slot-scope="scope" v-if="scope.row.expand">
          <div>{{ scope.row.categoryName }}</div>
          <div :class="scope.row.expand.isAutoOptimize== '2'?'text-danger':'text-blue'">
            <dict-tag :options="dict.type.auto_optimize_category_status"
                      :value="scope.row.expand.isAutoOptimize"></dict-tag>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="商品标签" align="center" prop="classifyLabel">
<!--        <template slot-scope="scope">-->
<!--          <el-tag v-for="(item, index) in goodsTagLabel(scope.row.expand)" :key="index" style="margin: 5px">-->
<!--            {{ item }}-->
<!--          </el-tag>-->
<!--        </template>-->
      </el-table-column>
      <el-table-column label="采集链接" align="center" prop="collectUrl">
        <template slot-scope="scope">
          <a :href="scope.row.collectUrl" style="color: #1890ff;" target="_blank">{{ scope.row.collectUrl }}</a>
        </template>
      </el-table-column>
      <el-table-column label="商品状态" align="center" prop="delFlag" width="100">
        <template v-if="scope.row.delFlag" slot-scope="scope">
          <div class="left">
            <i v-if="scope.row.delFlag == 0" class="el-icon-circle-check"><span>正常</span></i>
            <i v-if="scope.row.delFlag == 2" class="el-icon-circle-close"><span>已删除</span></i>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="进度" align="center" width="220">
        <template v-if="scope.row.expand" slot-scope="scope">
          <div class="left">
            <i v-if="scope.row.expand.editStatus == 0" class="el-icon-circle-close"><span>未编辑</span></i>
            <i v-if="scope.row.expand.editStatus == 1" class="el-icon-circle-check"><span>已编辑</span></i>
          </div>
          <div class="left">
            <i v-if="scope.row.expand.isFreight == 0" class="el-icon-circle-close"><span>未运费试算</span></i>
            <i v-if="scope.row.expand.isFreight == 1" class="el-icon-warning-outline"><span>等待运费试算</span></i>
            <i v-if="scope.row.expand.isFreight == 2" class="el-icon-loading"></i>
            <span v-if="scope.row.expand.isFreight == 2">运费试算中</span>
            <i v-if="scope.row.expand.isFreight == 3" class="el-icon-circle-check"><span>已运费试算</span></i>
            <i v-if="scope.row.expand.isFreight == 4" class="el-icon-circle-check"><span>运费试算失败</span></i>
            <span v-if="scope.row.expand.isFreight == 1 || scope.row.expand.isFreight == 2" class="changeHand"
                  @click="handleRefreshAdjust(scope.row)">重新计算</span>
          </div>
          <div class="left">
            <i v-if="scope.row.expand.isTranslate == 0" class="el-icon-circle-close"><span>未翻译</span></i>
            <i v-if="scope.row.expand.isTranslate == 1" class="el-icon-warning-outline"><span>等待翻译</span></i>
            <i v-if="scope.row.expand.isTranslate == 2" class="el-icon-loading"></i><span
            v-if="scope.row.expand.isTranslate == 2">翻译中</span>
            <i v-if="scope.row.expand.isTranslate == 3" class="el-icon-circle-check"><span>已翻译</span></i>
            <i v-if="scope.row.expand.isTranslate == 4" class="el-icon-remove-outline"><span>无需翻译</span></i>
            <span v-if="scope.row.expand.isTranslate == 1 || scope.row.expand.isTranslate == 2" class="changeHand"
                  @click="handleRefreshTranslate(scope.row)">重新翻译</span>
          </div>
          <div class="left">
            <i v-if="scope.row.expand.isUploadTest == 0" class="el-icon-circle-close"><span>未测试发布</span></i>
            <i v-if="scope.row.expand.isUploadTest == 1" class="el-icon-warning-outline"><span>等待测试发布</span></i>
            <i v-if="scope.row.expand.isUploadTest == 2" class="el-icon-circle-check"><span>测试通过</span></i>
            <i v-if="scope.row.expand.isUploadTest == 3" class="el-icon-circle-close">
              <span>测试失败</span>
              <span class="changeHand" @click="viewFailReason(scope.row)">查看原因</span>
            </i>
            <i v-if="scope.row.expand.isUploadTest == 4" class="el-icon-warning-outline"><span>无测试店铺</span></i>
            <i v-if="scope.row.expand.isUploadTest == 5" class="el-icon-circle-check"><span>无需测试</span></i>
            <span v-if="scope.row.expand.isUploadTest == 0 || scope.row.expand.isUploadTest == 3"
                  @click="ignoreUploadTestBtn(scope.row)" class="changeHand">忽略测试</span>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="采集人员" align="center" prop="collectUserName" width="80"/>
      <el-table-column label="操作" align="center" width="120">
        <template slot-scope="scope" v-if="scope.row.expand">
          <div class="leftbutton">
            <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)">修改</el-button>
            <el-button size="mini" type="text" icon="el-icon-edit-outline" @click="handleAdjust(scope.row)">
              {{ scope.row.expand.isFreight == 3 ? '查看运费' : '运费试算' }}
            </el-button>
            <el-button v-if="scope.row.expand.isTranslate != 4" size="mini" type="text" icon="el-icon-edit-outline"
                       @click="handleTranslate(scope.row)">
              {{ scope.row.expand.isTranslate == 3 ? '重新翻译' : '一键翻译' }}
            </el-button>
            <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)">删除
            </el-button>
            <el-button size="mini" type="text" icon="el-icon-crop" @click="releaseTest(scope.row)">测试发布
            </el-button>
            <el-button size="mini" type="text" icon="el-icon-circle-close"
                       v-if="scope.row.expand && scope.row.expand.isUploadTest == 1"
                       @click="cancelUploadTestBtn(scope.row)">
              取消测试发布
            </el-button>
            <el-button size="mini" type="text" icon="el-icon-mouse" @click="handleMerge(scope.row)">规格合并
            </el-button>
            <el-button size="mini" :loading="joinPersonProLoading" type="text" icon="el-icon-plus"
                       @click="handleJoin(scope.row)">加入个人产品库
            </el-button>
            <el-button size="mini" type="text" @click="openCertificateModal(scope.row)">资质证书</el-button>
            <el-button size="mini" type="text" icon="el-icon-edit" @click="asyncGather(scope.row)">同步</el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 公共采集库导入 -->
    <el-dialog title="公共采集库导入" :visible.sync="isImport" width="90%" :show-close="false" center>
      <div class="edit-box" v-loading="pubLoading">
        <DialogList ref="dialoglist"/>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button :disabled="pubLoading" type="primary" plain @click="handleIsImport">导 入</el-button>
        <el-button :disabled="pubLoading" @click="closeIsImport">取 消</el-button>
      </div>
    </el-dialog>
    <!--  创建资质证书组织  -->
    <createCertificate v-if="isOpenCertificateModal" :categoryList="categoryList"
                       @closeCertificateModal="closeCertificateModal"
                       :certificateData="certificateData" ideentity="operate"></createCertificate>
    <!--  选择商品主图  -->
    <chooseImgUrl v-if="isOpenChooseImgModal" :productId="productId" :gatherType="1" :imageList="chooseImageUrls"
                  :white="whiteImg"
                  :marketing="marketImg"
                  @close="closeChooseImgModal"></chooseImgUrl>
    <!--  编辑详情图弹窗  -->
    <editDetailImg v-if="isOpenEditDetailModal" :productId="productId" :white="whiteImg"
                   :marketing="marketImg" :editType="editType" :imageList="chooseImageUrls"
                   @close="closeEditDetailModal"></editDetailImg>

  </div>
</template>

<script>
import {
  listCollectProduct,
  delCollectProduct,
  addFreightTask,
  refreshFreightTask,
  addTranslateTask,
  refreshTranslateTask,
  ignoreTranslateTask,
  addToSellerPro,
  joinPublish,
  ignoreUploadTest,
  productUploadTestBatch,
  cancelUploadTest,
  updateCateGoryProById, synchronizationProductEdit, queryProgram, publishBatch
} from "@/api/persongather/collectProduct";
import {getBrand, getSelect} from "@/api/attribute"
import {
  selectlistCollectProductCategory,
  productUploadTest,
  getUploadTestFailReason
} from "@/api/gather/collectProductCategory";
import {userDict} from "@/api/gather/collectProductTask";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import DialogList from "../components/dialogList";
import createCertificate from "@/views/certificate/components/createCertificate.vue";
import chooseImgUrl from "@/views/gather/details/chooseImgUrl.vue";
import editDetailImg from "@/views/persongather/components/editDetailImg.vue";

export default {
  name: "PergoodsList",
  dicts: ['test_release_status', 'auto_optimize_category_status'],
  components: {
    Treeselect,
    DialogList,
    createCertificate,
    chooseImgUrl,
    editDetailImg
  },
  data() {
    return {
      testFailReason: '',//测试失败原因
      userDict: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      pubIds: [],
      // 非单个禁用
      single: true,
      pubSingle: true,
      // 非多个禁用
      multiple: true,
      pubMultiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 采集商品表格数据
      collectProductList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: true,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        categoryId: undefined,
        subject: undefined,
        collectUrl: undefined,
        isCollect: undefined,
        isEdit: undefined,
        isFreight: undefined,
        isTranslate: undefined,
        collectUserId: undefined,
        id: undefined,
        skuCode: undefined,
        brandId: undefined,
        isAddSellerProduct: undefined,
        isAutoOptimize: undefined
      },
      // 标签列表
      tagList: [],
      // 类目列表
      categoryList: [],
      // 是否为采集商品
      collectList: [
        {
          value: 0,
          label: '是'
        },
        {
          value: 1,
          label: '否'
        }
      ],
      // 编辑列表
      editList: [
        {
          value: 0,
          label: '否'
        },
        {
          value: 1,
          label: '是'
        }
      ],
      // 运费试算列表
      freightList: [
        {
          value: 0,
          label: '未运费试算'
        },
        {
          value: 1,
          label: '等待运费试算'
        },
        {
          value: 2,
          label: '运费试算中'
        },
        {
          value: 3,
          label: '已运费试算'
        }
      ],
      // 翻译列表
      translateList: [
        {
          value: 0,
          label: '未翻译'
        },
        {
          value: 1,
          label: '等待翻译'
        },
        {
          value: 2,
          label: '翻译中'
        },
        {
          value: 3,
          label: '已翻译'
        },
        {
          value: 4,
          label: '无需翻译'
        }
      ],
      addSellerProductList: [
        {
          value: 0,
          label: '已加入个人产品库'
        },
        {
          value: 1,
          label: '未加入个人产品库'
        }
      ],
      // 品牌列表
      brandList: [],
      isImport: false,
      pubGoodsList: [],
      pubLoading: false,
      isOpenCertificateModal: false,//是否打开
      certificateData: "",//资质证书数据
      isOpenChooseImgModal: false,//是否打开选择图片弹窗
      chooseImageUrls: "",
      imgType: "",
      productId: "",
      whiteImg: "",//白底图
      marketImg: "",//白底图
      isOpenEditDetailModal: false,//是否打开编辑详情图弹窗
      editType: "",//编辑类型 0:详情图，1：商品主图
      joinPersonProLoading: false,//加入个人产品库loading
    };
  },
  computed: {
    // 标签
    goodsTagLabel() {
      if (this.tagList.length > 0) {
        return (row) => {
          if (row && row.classifyLabel) {
            try {
              const defaultList = row.classifyLabel.split(',').filter(item => !!item)
              const classifyLabelList = []
              for (let i = 0; i < defaultList.length; i++) {
                for (let k = 0; k < this.tagList.length; k++) {
                  if (defaultList[i] == this.tagList[k].value) {
                    classifyLabelList.push(this.tagList[k].lable)
                  }
                }
              }
              return classifyLabelList
            } catch (e) {
              return []
            }
          } else return []
        }
      } else return []
    }
  },
  created() {
    this.getGoodsCategory();
    this.getTagList();
    this.getBrandList();
    this.getList();
    userDict({}).then(response => {
      this.userDict = response;
    }).catch(error => {
    })
  },
  methods: {
    // 打开编辑详情图弹窗
    openEditDetailImg(row, type) {
      this.productId = row.id
      this.editType = type
      if (type == '0') {
        this.chooseImageUrls = row.detailImg
      } else {
        this.whiteImg = row.white
        this.marketImg = row.marketing
        this.chooseImageUrls = row.imageURLs
      }
      this.isOpenEditDetailModal = true
    },
    // 关闭选择商品主图弹窗
    closeEditDetailModal(e) {
      console.log('eee', e)
      if (e == 'isRef') {
        this.getList()
      }
      this.isOpenEditDetailModal = false
    },
    // 打开选择商品主图模态框
    openChooseImage(row) {
      this.productId = row.id
      this.chooseImageUrls = row.imageURLs
      this.whiteImg = row.white
      this.marketImg = row.marketing
      this.isOpenChooseImgModal = true
    },
    // 关闭选择商品主图弹窗
    closeChooseImgModal(e) {
      console.log('eee', e)
      if (e == 'isRef') {
        this.getList()
      }
      this.isOpenChooseImgModal = false
    },
    // 生成报告
    handleReporting() {
      this.$modal.confirm('是否确定生成报告？').then(() => {
        this.download('gather/sellerStoreProductInfringingKeywords/collectProductKeyWordsDetection', {
          ...this.queryParams
        }, `productUnifiedTakedown_${new Date().getTime()}.xlsx`)
      })
    },
    // 查看资质方案
    openCertificateModal(row) {
      let data = {
        collectProductId: row.id
      }
      queryProgram(data).then(res => {
        this.certificateData = res.data
        this.isOpenCertificateModal = true
      })
    },
    // 关闭资质方案组件
    closeCertificateModal(e) {
      if (e == 'isRef') {
        this.getList()
      }
      this.isOpenCertificateModal = false
    },
    // 批量测试发布
    handleUploadTestBatch() {
      const ids = this.ids;
      const params = {
        collectProductIds: ids.join(','),
        type: '1'
      }
      this.$modal.confirm('是否确认批量测试发布商品编号为"' + ids + '"的数据项？').then(() => {
        this.loading = true;
        return productUploadTestBatch(params);
      }).then(() => {
        this.loading = false;
        this.getList();
        this.$modal.msgSuccess("测试发布成功");
      }).catch(() => {
      }).finally(() => {
        this.loading = false;
      });
    },
    // 批量刊登
    handlePublishBatch() {
      const ids = this.ids;
      this.$modal.confirm('是否确认批量刊登个人产品库？').then(() => {
        this.loading = true;
        return publishBatch(ids);
      }).then(() => {
        this.loading = false;
        this.getList();
        this.$modal.msgSuccess("刊登成功，请到个人产品库中查看");
      }).catch(() => {
      }).finally(() => {
        this.loading = false;
      });
    },
    // 取消测试发布
    cancelUploadTestBtn(row) {
      const ids = row.id
      const params = {
        collectProductId: ids,
        type: '2'
      }
      this.$modal.confirm('是否确认取消测试发布商品编号为"' + ids + '"的数据项？').then(() => {
        this.loading = true;
        return cancelUploadTest(params);
      }).then(() => {
        this.loading = false;
        this.getList();
        this.$modal.msgSuccess("取消成功");
      }).catch(() => {
      }).finally(() => {
        this.loading = false;
      });
    },
    // 忽略测试
    ignoreUploadTestBtn(row) {
      if (row.expand && (row.expand.isUploadTest == 0 || row.expand.isUploadTest == 3)) {
        this.$modal.confirm('是否忽略测试？').then(() => {
          return ignoreUploadTest(row.id);
        }).then(() => {
          this.getList();
        }).catch((e) => {
        }).finally(() => {
        });
      }
    },
    // 查看失败原因
    viewFailReason(row) {
      this.testFailReason = ''
      let data = {
        collectProductId: row.id
      }
      getUploadTestFailReason(data).then(response => {
        this.$alert(response, '测试失败原因', {
          confirmButtonText: '确定',
          callback: action => {
          }
        });
      });
    },
    /** 查询采集商品列表 */
    getList() {
      this.loading = true;
      listCollectProduct(this.queryParams).then(response => {
        this.collectProductList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 标签列表
    getTagList() {
      getSelect().then(res => {
        this.tagList = res.data
      });
    },
    // 商品类目
    getGoodsCategory() {
      selectlistCollectProductCategory().then(response => {
        this.categoryList = this.handleTree(response.data, "id", "parentId");
      });
    },
    /** 转换采集商品类目数据结构 */
    normalizer(node) {
      if (node.children && !node.children.length) {
        delete node.children;
      }
      return {
        id: node.id,
        label: node.name,
        children: node.children
      };
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    pubChange(selection) {
      this.pubIds = selection.map(item => item.id)
      this.pubSingle = selection.length !== 1
      this.pubMultiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.$router.push(`/gather/details/` + 'add')
    },
    // 公共产品库导入打开弹框
    handleImport() {
      this.isImport = true;
    },
    closeIsImport() {
      this.isImport = false;
      this.$refs.dialoglist.resetQuery();
    },
    // 导入操作
    handleIsImport() {
      const ids = (this.$refs.dialoglist.ids).toString();
      if (ids) {
        this.$modal.confirm('是否将商品编号为"' + ids + '"的数据导入个人采集库？').then(() => {
          const params = {
            prods: ids
          }
          this.pubLoading = true;
          return addToSellerPro(params);
        }).then(() => {
          this.pubLoading = false;
          this.getList();
          this.isImport = false;
          this.$modal.msgSuccess("导入成功");
          this.$refs.dialoglist.resetQuery();
        }).catch(() => {
        }).finally(() => {
          this.pubLoading = false;
        });
      } else {
        this.$modal.msgError("请选择商品");
      }
    },
    // 同步采集商品
    asyncGather(row) {
      synchronizationProductEdit({collectProductId: row.id}).then(res => {
        this.$message.success(res.msg)
      })
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.$router.push(`/gather/details/` + row.id);
      // if (row.expand && row.expand.productStatus == 0) {
      // } else {
      //   this.$modal.msgError("请先下架商品在进行编辑");
      // }
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除采集商品编号为"' + ids + '"的数据项？').then(() => {
        this.loading = true;
        return delCollectProduct(ids);
      }).then(() => {
        this.loading = false;
        this.getList();
        this.$modal.msgSuccess("删除成功，删除的商品还在列表中，只是放到了最后");
      }).catch(() => {
      }).finally(() => {
        this.loading = false;
      });
    },
    // 测试发布
    releaseTest(row) {
      this.$modal.confirm('是否要测试发布？').then(() => {
        const params = {
          collectProductId: row.id,
          type: '1'
        }
        productUploadTest(params).then(res => {
          this.$message.success(res.msg)
          this.getList()
        })
      })
    },
    // 加入个人产品库
    handleJoin(row) {
      var delFlag = row.delFlag;
      if (delFlag == 2) {
        this.$modal.msgError("商品已删除不能上架！");
        return;
      }
      var bool = false;
      if (row.expand.editStatus == '1' && row.expand.isFreight == '3' && (row.expand.isUploadTest == '2' || row.expand.isUploadTest == '5') && (row.expand.isTranslate == '3' || row.expand.isTranslate == '4')) {
        bool = true;
      } else if (row.expand.classifyLabel == 1719179918137212929) {
        bool = true;
      } else {
        this.$modal.msgError("进度栏有未完成项");
      }
      if (!bool)
        return;
      this.$modal.confirm('是否加入个人产品库？').then(() => {
        this.joinPersonProLoading = true
        const params = {
          sellerCollectProId: row.id
        }
        joinPublish(params).then(res => {
          this.$message.success(res.msg)
          this.joinPersonProLoading = false
          this.getList()
        }).finally(() => {
          this.joinPersonProLoading = false
        })
      })
    },
    // 运费试算
    handleAdjust(row) {
      if (row.expand && row.expand.editStatus == 1) {
        if (row.expand.isFreight == 3) {
          this.$router.push(`/gather/areaCharge/` + row.id)
        } else if (row.expand.isFreight == 0) {
          this.$modal.confirm('是否进行运费试算？').then(() => {
            const params = {
              collectProductId: row.id,
              type: '1'
            }
            return addFreightTask(params);
          }).then(() => {
            this.getList();
          }).catch((e) => {
          }).finally(() => {
          });
        } else if (row.expand.isFreight == 1) {
          this.$modal.msgWarning("等待运费试算");
        } else if (row.expand.isFreight == 2) {
          this.$modal.msgWarning("运费试算中");
        }
      } else {
        this.$modal.msgError("请先编辑商品");
      }
    },
    // 重新运费试算
    handleRefreshAdjust(row) {
      if (row.expand && (row.expand.isTranslate == 3 || row.expand.isTranslate == 1 || row.expand.isTranslate == 2)) {
        this.$modal.confirm('是否重新运费试算？').then(() => {
          const params = {
            collectProductId: row.id,
            type: '1'
          }
          refreshFreightTask(params);
          this.$modal.msgSuccess("刷新成功");
        }).then(() => {
          this.getList();
        }).catch((e) => {
        }).finally(() => {
        });
      }
    },
    // 加入翻译
    handleTranslate(row) {
      if (row.expand && row.expand.editStatus == 1) {
        if (row.expand.isTranslate == 0) {
          this.$modal.confirm('是否进行翻译？').then(() => {
            const params = {
              collectProductId: row.id,
              type: '1'
            }
            return addTranslateTask(params);
          }).then(() => {
            this.getList();
          }).catch((e) => {
          }).finally(() => {
          });
        } else if (row.expand.isTranslate == 1) {
          this.$modal.msgWarning("等待翻译");
        } else if (row.expand.isTranslate == 2) {
          this.$modal.msgWarning("翻译中");
        } else if (row.expand.isTranslate == 3) {
          this.handleRefreshTranslate(row);
        } else if (row.expand.isTranslate == 4) {
          this.$modal.msgWarning("无需翻译");
        }
      } else {
        this.$modal.msgError("请先编辑商品");
      }
    },
    // 重新翻译
    handleRefreshTranslate(row) {
      if (row.expand && (row.expand.isTranslate == 3 || row.expand.isTranslate == 1 || row.expand.isTranslate == 2)) {
        this.$modal.confirm('是否重新翻译？').then(() => {
          const params = {
            collectProductId: row.id,
            type: '1'
          }
          refreshTranslateTask(params);
          this.$modal.msgSuccess("刷新成功");
        }).then(() => {
          this.getList();
        }).catch((e) => {
        }).finally(() => {
        });
      }
    },
    // 忽略翻译
    ignoreTranslateBtn(row) {
      if (row.expand && row.expand.isTranslate == 0) {
        this.$modal.confirm('是否忽略翻译？').then(() => {
          return ignoreTranslateTask(row.id);
        }).then(() => {
          this.getList();
        }).catch((e) => {
        }).finally(() => {
        });
      }
    },
    // 获取品牌选择列表
    getBrandList() {
      getBrand().then(res => {
        this.brandList = res.data
      });
    },
    // 规格合并
    handleMerge(row) {
      this.$modal.confirm('当前只支持两个规格合并为一个规格').then(() => {
        updateCateGoryProById({proId: row.id}).then(res => {
          this.$message.success(res.msg);
          this.getList();
        })
      })
    },
  }
};
</script>

<style lang="scss">
.left {
  width: 100%;
  text-align: left;

  .changeHand {
    color: #00afff;
    font-size: 12px;
  }

  span {
    padding: 0 4px;
    color: #606266;
  }

  .inlineblock {
    display: inline-block;
    padding: 4px 2px;
    background: none;
    font-size: 10px;
  }
}

.leftbutton {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;

  .el-button {
    margin-left: 0;

    span {
      padding: 0 4px;
    }
  }
}

.pointer {
  cursor: pointer;
}

.el-icon-circle-close {
  color: #F56C6C;
}

.el-icon-circle-check {
  color: #67C23A;
}

.el-icon-warning-outline {
  color: #E6A23C;
}
</style>
